﻿<hi:Common_WapHeader runat="server" />
<div class="pbox" style="margin-bottom:-20px;">
    <div class="input-group form-search">
        <input id="txtKeywords" type="text" class="form-control search-query">        
        <span class="input-group-btn">
            <button type="submit" class="btn btn-warning" data-type="last" onclick="searchs()">搜索</button>
        </span>
    </div>
</div>
	<div class="pbox">
		<div class="list-group">
			<hi:WapTemplatedRepeater id="rptCategories" templatefile="/Tags/skin-Common_Categories.ascx"
        runat="server" />
		</div>
	</div>
<hi:Common_WapFooter runat="server" />

<script type="text/javascript">
    function searchs() {
        var key = $("#txtKeywords").val();
        var str = window.location.search;

        var categoryId;
        if (-1 == str.indexOf("&keyWord=")) {
            categoryId = str.substring(str.indexOf("categoryId=") + 11);
        } else {
            categoryId = str.substring(str.indexOf("categoryId=") + 11, str.indexOf("&keyWord="));
        }

        var url = "/wapshop/ProductList.aspx?categoryId=" + categoryId + "&keyWord=" + escape(key);

        window.location.href = url;
    }

    $(document).ready(function () {
        var str = window.location.search;
        if (str.indexOf("keyWord=") != -1) {
            var keyWord = str.substring(str.indexOf("keyWord=") + 8);
            if (keyWord.length > 0) {
                $("#txtKeywords").val(keyWord);
            }
        }
    });


    $(".hfooter .glyphicon-refresh").click(function () {
        location.reload();
    })

    $(".hfooter .glyphicon-arrow-left").click(function () {
        history.go(-1);
    })

    //隐藏右上角菜单
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    });

    //隐藏底部菜单
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideToolbar');
    });


    function goUrl(url) {
//        alert(url);
        location.replace(url);

    }

    $(function () {
        var categoryItems = $('a.categoryItem');
        var cateogryId, url;
        $.each(categoryItems, function (i, item) {
            cateogryId = $(item).attr('value');
            if ($(item).attr('name') == "True")
                url = '?categoryId=' + cateogryId;
            else
                url = '/wapshop/ProductList.aspx?categoryId=' + cateogryId;
            $(item).attr('onclick', 'goUrl("'+url+'")').attr('href', 'javascript:;');

        });

    });

</script>
